<template>
  <el-dialog
    title="拒绝"
    class="task-refuse-body"
    :visible.sync="dialogVisible"
    :destroy-on-close="true"
    :show-close="false"
    append-to-body
    width="450px"
    :close-on-click-modal="false">
    <el-form :model="model" :rules="rules" ref="form">
      <el-form-item prop="content">
        <el-input type="textarea" :autosize="{minRows: 3}" v-model="model.content" placeholder="请输入拒绝理由"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" style="display: flex;justify-content: center;">
      <el-button type="primary"
                 @click="cancel"
                 native-type="submit">取消
      </el-button>
      <el-button type="primary"
                 @click="submit"
                 native-type="submit">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'refuse',
  data () {
    return {
      dialogVisible: false,
      model: {
        content: ''
      },
      rules: {
        content: [{ required: true, message: '请输入拒绝理由' }]
      }
    }
  },
  methods: {
    open () {
      this.model.content = ''
      this.dialogVisible = true
      return new Promise((resolve) => {
        this._resolve = resolve
      })
    },
    cancel (flag = false) {
      if (flag === false) {
        this._resolve({
          content: false
        })
      }
      this.dialogVisible = false
    },
    async submit () {
      await this.$refs.form.validate()
      this._resolve({
        content: this.model.content
      })
      this.cancel(true)
    }
  }
}
</script>

<style scoped>

</style>
